﻿using System;
using System.Threading.Tasks;
using Abp.EntityFrameworkCore;
using Abp.IdentityServer4;
using AVISOutBound.SSOServer.Authorization.Members;
using IdentityServer4.EntityFramework.Entities;
using IdentityServer4.EntityFramework.Extensions;
using IdentityServer4.EntityFramework.Interfaces;
using IdentityServer4.EntityFramework.Options;
using Microsoft.EntityFrameworkCore;
using AVISOutBound.SSOServer.EntityFrameworkCore.Models;
using AVISOutBound.SSOServer.Orders.AbgExchangeRateses;
using AVISOutBound.SSOServer.Orders.AbgOrderPayLogs;
using AVISOutBound.SSOServer.Orders.AbgRefundOrders;
using Abp.Configuration;

namespace AVISOutBound.SSOServer.EntityFrameworkCore
{
    public class SSOServerDbContext : AbpDbContext , IConfigurationDbContext
    {
        private readonly ConfigurationStoreOptions _configurationStoreOptions = new ConfigurationStoreOptions();

        public SSOServerDbContext(DbContextOptions<SSOServerDbContext> options)
            : base(options)
        {
        }

        public SSOServerDbContext(DbContextOptions<SSOServerDbContext> options, ConfigurationStoreOptions configurationStoreOptions)
            : base(options)
        {
            _configurationStoreOptions = configurationStoreOptions;
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            // lulus:配置客户端和资源相关表
            builder.ConfigureClientContext(_configurationStoreOptions);
            //// lulus:配置授权相关表
            //builder.ConfigurePersistedGrantEntity();

            base.OnModelCreating(builder);
            // Customize the ASP.NET Identity model and override the defaults if needed.
            // For example, you can rename the ASP.NET Identity table names and more.
            // Add your customizations after calling base.OnModelCreating(builder);
        }

        public Task<int> SaveChangesAsync()
        {
            return base.SaveChangesAsync();
        }
        public virtual DbSet<Member> Members { get; set; }
        public virtual DbSet<avisOBOrder> AvisOBOrder { get; set; }
        public DbSet<Client> Clients { get; set; }
        public DbSet<IdentityResource> IdentityResources { get; set; }
        public DbSet<ApiResource> ApiResources { get; set; }
        //public DbSet<PersistedGrantEntity> PersistedGrants { get; set; }
        public DbSet<AbgExchangeRates> AbgExchangeRateses { get; set; }
        public DbSet<AbgOrderPayLog> AbgOrderPayLogs { get; set; }
        public DbSet<AbgRefundOrder> AbgRefundOrders { get; set; }
        public DbSet<Setting> Settings { get; set; }
    }
}
